package com.snail.controller;

import com.snail.model.pojo.media.BizCollectionWorks;
import com.snail.model.pojo.media.BizWorks;
import com.snail.model.query.media.WorksPageQuery;
import com.snail.model.query.media.WorksReviewPageQuery;
import com.snail.model.vo.media.BizWorksReviewVo;
import com.snail.model.vo.media.BizWorksVo;
import com.snail.result.PageResult;
import com.snail.result.Result;
import com.snail.service.BizWorksService;
import com.snail.utils.SecurityUtils;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Monica
 * @description
 * @date 2025/8/16 15:17
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/works")
public class BizWorksController {

    private final BizWorksService bizWorksService;

    @PostMapping("/createWorks")
    private Result<BizWorks> createWorks(BizWorks bizWorks){
        Long userId = SecurityUtils.getCurrentUser().getUserId();
        bizWorks.setUserId(userId);
        bizWorks.setStatus(2);
        BizWorks  works = bizWorksService.createWorks(bizWorks);
        return Result.success(works);
    }


    @PostMapping("/getWorksList")
    private PageResult<BizWorksVo> getWorksList(@RequestBody WorksPageQuery worksPageQuery){
        Long userId = SecurityUtils.getCurrentUser().getUserId();
        worksPageQuery.setUserId(userId);
        return PageResult.success(bizWorksService.getWorksList(worksPageQuery));
    }

    @PostMapping("/getWorksListForVisitor")
    private PageResult<BizWorksVo> getWorksListForVisitor(@RequestBody WorksPageQuery worksPageQuery){

        return PageResult.success(bizWorksService.getWorksList(worksPageQuery));
    }

    @PostMapping("/updateWorks")
    private Result<BizWorks> updateWorks(@RequestBody BizWorks bizWorks){
        Long userId = SecurityUtils.getCurrentUser().getUserId();
        bizWorks.setUserId(userId);
        bizWorks.setStatus(2);
        bizWorksService.updateById(bizWorks);
        return Result.success(bizWorks);
    }

    @PostMapping("/deleteWorks")
    private Result<BizWorks> deleteWorks(@RequestBody Integer id){
        bizWorksService.removeById(id);
        return Result.success();
    }

    @PostMapping("/getWorksListByUserId")
    private Result<List<BizWorks>> getWorksListByUserId(String name){
        Long id = SecurityUtils.getCurrentUser().getUserId();
        return Result.success(bizWorksService.getWorksListByUserId(id,name));
    }

    @PostMapping("/getWorksListByUserIdForVisitor")
    private Result<List<BizWorks>> getWorksListByUserIdForVisitor(Long id,String name){

        return Result.success(bizWorksService.getWorksListByUserId(id,name));
    }

    @GetMapping("/getCollectionWorks")
    public Result<List<BizWorks>> getCollectionWorks(Integer collectionId) {
        List<BizWorks> list = bizWorksService.getCollectionWorks(collectionId);
        return Result.success(list);
    }

    @GetMapping("/getWorksById")
    public Result<BizWorksVo> getWorksById(Long id) {
        BizWorksVo bizWorks = bizWorksService.getWorksById(id);
        return Result.success(bizWorks);
    }


    @GetMapping("/getWorksReviewList")
    private PageResult<BizWorksReviewVo> getWorksReviewList(WorksReviewPageQuery worksReviewPageQuery){;

        return PageResult.success(bizWorksService.getWorksReviewList(worksReviewPageQuery));
    }

}
